home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / CIncludes / SCSI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-11  |  39.8 KB  |  997 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        SCSI.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a3  ETO #16, MPW prerelease.  Friday, November 11, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __SCSI__
  18. #define __SCSI__
  19.  
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifndef __MIXEDMODE__
  27. #include <MixedMode.h>
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if GENERATINGPOWERPC
  35. #pragma options align=mac68k
  36. #endif
  37.  
  38. #ifdef __CFM68K__
  39. #pragma lib_export on
  40. #endif
  41.  
  42.  
  43. enum {
  44.     scInc                        = 1,
  45.     scNoInc                        = 2,
  46.     scAdd                        = 3,
  47.     scMove                        = 4,
  48.     scLoop                        = 5,
  49.     scNop                        = 6,
  50.     scStop                        = 7,
  51.     scComp                        = 8
  52. };
  53.  
  54. /* SCSI Manager errors */
  55. enum {
  56.     scCommErr                    = 2,                            /* communications error, operation timeout */
  57.     scArbNBErr                    = 3,                            /* arbitration timeout waiting for not BSY */
  58.     scBadParmsErr                = 4,                            /* bad parameter or TIB opcode */
  59.     scPhaseErr                    = 5,                            /* SCSI bus not in correct phase for attempted operation */
  60.     scCompareErr                = 6,                            /* data compare error */
  61.     scMgrBusyErr                = 7,                            /* SCSI Manager busy  */
  62.     scSequenceErr                = 8,                            /* attempted operation is out of sequence */
  63.     scBusTOErr                    = 9,                            /* CPU bus timeout */
  64.     scComplPhaseErr                = 10                            /* SCSI bus wasn't in Status phase */
  65. };
  66.  
  67. /* Signatures */
  68. enum {
  69.     sbSIGWord                    = 0x4552,                        /* signature word for Block 0 ('ER') */
  70.     sbMac                        = 1,                            /* system type for Mac */
  71.     pMapSIG                        = 0x504D,                        /* partition map signature ('PM') */
  72.     pdSigWord                    = 0x5453
  73. };
  74.  
  75. enum {
  76.     oldPMSigWord                = pdSigWord,
  77.     newPMSigWord                = pMapSIG
  78. };
  79.  
  80. /* Driver Descriptor Map */
  81. struct Block0 {
  82.     unsigned short                    sbSig;                        /* unique value for SCSI block 0 */
  83.     unsigned short                    sbBlkSize;                    /* block size of device */
  84.     unsigned long                    sbBlkCount;                    /* number of blocks on device */
  85.     unsigned short                    sbDevType;                    /* device type */
  86.     unsigned short                    sbDevId;                    /* device id */
  87.     unsigned long                    sbData;                        /* not used */
  88.     unsigned short                    sbDrvrCount;                /* driver descriptor count */
  89.     unsigned long                    ddBlock;                    /* 1st driver's starting block */
  90.     unsigned short                    ddSize;                        /* size of 1st driver (512-byte blks) */
  91.     unsigned short                    ddType;                        /* system type (1 for Mac+) */
  92.     unsigned short                    ddPad[243];                    /* ARRAY[0..242] OF INTEGER; not used */
  93. };
  94. typedef struct Block0 Block0;
  95.  
  96. /* Partition Map Entry */
  97. struct Partition {
  98.     unsigned short                    pmSig;                        /* unique value for map entry blk */
  99.     unsigned short                    pmSigPad;                    /* currently unused */
  100.     unsigned long                    pmMapBlkCnt;                /* # of blks in partition map */
  101.     unsigned long                    pmPyPartStart;                /* physical start blk of partition */
  102.     unsigned long                    pmPartBlkCnt;                /* # of blks in this partition */
  103.     unsigned char                    pmPartName[32];                /* ASCII partition name */
  104.     unsigned char                    pmParType[32];                /* ASCII partition type */
  105.     unsigned long                    pmLgDataStart;                /* log. # of partition's 1st data blk */
  106.     unsigned long                    pmDataCnt;                    /* # of blks in partition's data area */
  107.     unsigned long                    pmPartStatus;                /* bit field for partition status */
  108.     unsigned long                    pmLgBootStart;                /* log. blk of partition's boot code */
  109.     unsigned long                    pmBootSize;                    /* number of bytes in boot code */
  110.     unsigned long                    pmBootAddr;                    /* memory load address of boot code */
  111.     unsigned long                    pmBootAddr2;                /* currently unused */
  112.     unsigned long                    pmBootEntry;                /* entry point of boot code */
  113.     unsigned long                    pmBootEntry2;                /* currently unused */
  114.     unsigned long                    pmBootCksum;                /* checksum of boot code */
  115.     unsigned char                    pmProcessor[16];            /* ASCII for the processor type */
  116.     unsigned short                    pmPad[188];                    /* 512 bytes long currently unused */
  117. };
  118. typedef struct Partition Partition;
  119.  
  120. /* TIB instruction */
  121. struct SCSIInstr {
  122.     unsigned short                    scOpcode;
  123.     long                            scParam1;
  124.     long                            scParam2;
  125. };
  126. typedef struct SCSIInstr SCSIInstr;
  127.  
  128. extern pascal OSErr SCSIReset(void)
  129.  TWOWORDINLINE(0x4267, 0xA815);
  130. extern pascal OSErr SCSIGet(void)
  131.  THREEWORDINLINE(0x3F3C, 0x0001, 0xA815);
  132. extern pascal OSErr SCSISelect(short targetID)
  133.  THREEWORDINLINE(0x3F3C, 0x0002, 0xA815);
  134. extern pascal OSErr SCSICmd(Ptr buffer, short count)
  135.  THREEWORDINLINE(0x3F3C, 0x0003, 0xA815);
  136. extern pascal OSErr SCSIRead(Ptr tibPtr)
  137.  THREEWORDINLINE(0x3F3C, 0x0005, 0xA815);
  138. extern pascal OSErr SCSIRBlind(Ptr tibPtr)
  139.  THREEWORDINLINE(0x3F3C, 0x0008, 0xA815);
  140. extern pascal OSErr SCSIWrite(Ptr tibPtr)
  141.  THREEWORDINLINE(0x3F3C, 0x0006, 0xA815);
  142. extern pascal OSErr SCSIWBlind(Ptr tibPtr)
  143.  THREEWORDINLINE(0x3F3C, 0x0009, 0xA815);
  144. extern pascal OSErr SCSIComplete(short *stat, short *message, unsigned long wait)
  145.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA815);
  146. extern pascal short SCSIStat(void)
  147.  THREEWORDINLINE(0x3F3C, 0x000A, 0xA815);
  148. extern pascal OSErr SCSISelAtn(short targetID)
  149.  THREEWORDINLINE(0x3F3C, 0x000B, 0xA815);
  150. extern pascal OSErr SCSIMsgIn(short *message)
  151.  THREEWORDINLINE(0x3F3C, 0x000C, 0xA815);
  152. extern pascal OSErr SCSIMsgOut(short message)
  153.  THREEWORDINLINE(0x3F3C, 0x000D, 0xA815);
  154. /*——————————————————————— New SCSI Manager Interface ———————————————————————*/
  155.  
  156. enum {
  157.     scsiVERSION                    = 43
  158. };
  159.  
  160. /* SCSI Manager function codes */
  161. enum {
  162.     SCSINop                        = 0x00,                            /* Execute nothing                                         */
  163.     SCSIExecIO                    = 0x01,                            /* Execute the specified IO                             */
  164.     SCSIBusInquiry                = 0x03,                            /* Get parameters for entire path of HBAs                 */
  165.     SCSIReleaseQ                = 0x04,                            /* Release the frozen SIM queue for particular LUN         */
  166.     SCSIAbortCommand            = 0x10,                            /* Abort the selected Control Block                      */
  167.     SCSIResetBus                = 0x11,                            /* Reset the SCSI bus                                      */
  168.     SCSIResetDevice                = 0x12,                            /* Reset the SCSI device                                  */
  169.     SCSITerminateIO                = 0x13,                            /* Terminate any pending IO                              */
  170.     SCSIGetVirtualIDInfo        = 0x80,                            /* Find out which bus old ID is on                         */
  171.     SCSILoadDriver                = 0x82,                            /* Load a driver for a device ident                     */
  172.     SCSIOldCall                    = 0x84,                            /* XPT->SIM private call for old-API                     */
  173.     SCSICreateRefNumXref        = 0x85,                            /* Register a DeviceIdent to drvr RefNum xref             */
  174.     SCSILookupRefNumXref        = 0x86,                            /* Get DeviceIdent to drvr RefNum xref                     */
  175.     SCSIRemoveRefNumXref        = 0x87,                            /* Remove a DeviceIdent to drvr RefNum xref             */
  176.     SCSIRegisterWithNewXPT        = 0x88,                            /* XPT has changed - SIM needs to re-register itself     */
  177.     vendorUnique                = 0xC0                            /* 0xC0 thru 0xFF */
  178. };
  179.  
  180. /* SCSI Callback Procedure Prototypes */
  181. typedef pascal void (*SCSICallbackProcPtr)(void *scsiPB);
  182. typedef void (*AENCallbackProcPtr)(void);
  183. typedef OSErr (*SIMInitProcPtr)(Ptr SIMinfoPtr);
  184. typedef void (*SIMActionProcPtr)(void *scsiPB, Ptr SIMGlobals);
  185. typedef void (*SCSIProcPtr)(void);
  186. typedef void (*SCSIMakeCallbackProcPtr)(void *scsiPB);
  187. typedef long (*SCSIInterruptPollProcPtr)(Ptr SIMGlobals);
  188.  
  189. #if GENERATINGCFM
  190. typedef UniversalProcPtr SCSICallbackUPP;
  191. typedef UniversalProcPtr AENCallbackUPP;
  192. typedef UniversalProcPtr SIMInitUPP;
  193. typedef UniversalProcPtr SIMActionUPP;
  194. typedef UniversalProcPtr SCSIUPP;
  195. typedef UniversalProcPtr SCSIMakeCallbackUPP;
  196. typedef UniversalProcPtr SCSIInterruptPollUPP;
  197. #else
  198. typedef SCSICallbackProcPtr SCSICallbackUPP;
  199. typedef AENCallbackProcPtr AENCallbackUPP;
  200. typedef SIMInitProcPtr SIMInitUPP;
  201. typedef SIMActionProcPtr SIMActionUPP;
  202. typedef SCSIProcPtr SCSIUPP;
  203. typedef SCSIMakeCallbackProcPtr SCSIMakeCallbackUPP;
  204. typedef SCSIInterruptPollProcPtr SCSIInterruptPollUPP;
  205. #endif
  206.  
  207. enum {
  208.     uppSCSICallbackProcInfo = kPascalStackBased
  209.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void*))),
  210.     uppAENCallbackProcInfo = kCStackBased,
  211.     uppSIMInitProcInfo = kCStackBased
  212.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  213.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Ptr))),
  214.     uppSIMActionProcInfo = kCStackBased
  215.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void*)))
  216.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr))),
  217.     uppSCSIProcInfo = kCStackBased,
  218.     uppSCSIMakeCallbackProcInfo = kCStackBased
  219.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void*))),
  220.     uppSCSIInterruptPollProcInfo = kCStackBased
  221.          | RESULT_SIZE(SIZE_CODE(sizeof(long)))
  222.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Ptr)))
  223. };
  224.  
  225. #if GENERATINGCFM
  226. #define NewSCSICallbackProc(userRoutine)        \
  227.         (SCSICallbackUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSICallbackProcInfo, GetCurrentArchitecture())
  228. #define NewAENCallbackProc(userRoutine)        \
  229.         (AENCallbackUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppAENCallbackProcInfo, GetCurrentArchitecture())
  230. #define NewSIMInitProc(userRoutine)        \
  231.         (SIMInitUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSIMInitProcInfo, GetCurrentArchitecture())
  232. #define NewSIMActionProc(userRoutine)        \
  233.         (SIMActionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSIMActionProcInfo, GetCurrentArchitecture())
  234. #define NewSCSIProc(userRoutine)        \
  235.         (SCSIUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIProcInfo, GetCurrentArchitecture())
  236. #define NewSCSIMakeCallbackProc(userRoutine)        \
  237.         (SCSIMakeCallbackUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIMakeCallbackProcInfo, GetCurrentArchitecture())
  238. #define NewSCSIInterruptPollProc(userRoutine)        \
  239.         (SCSIInterruptPollUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIInterruptPollProcInfo, GetCurrentArchitecture())
  240. #else
  241. #define NewSCSICallbackProc(userRoutine)        \
  242.         ((SCSICallbackUPP) (userRoutine))
  243. #define NewAENCallbackProc(userRoutine)        \
  244.         ((AENCallbackUPP) (userRoutine))
  245. #define NewSIMInitProc(userRoutine)        \
  246.         ((SIMInitUPP) (userRoutine))
  247. #define NewSIMActionProc(userRoutine)        \
  248.         ((SIMActionUPP) (userRoutine))
  249. #define NewSCSIProc(userRoutine)        \
  250.         ((SCSIUPP) (userRoutine))
  251. #define NewSCSIMakeCallbackProc(userRoutine)        \
  252.         ((SCSIMakeCallbackUPP) (userRoutine))
  253. #define NewSCSIInterruptPollProc(userRoutine)        \
  254.         ((SCSIInterruptPollUPP) (userRoutine))
  255. #endif
  256.  
  257. #if GENERATINGCFM
  258. #define CallSCSICallbackProc(userRoutine, scsiPB)        \
  259.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSCSICallbackProcInfo, (scsiPB))
  260. #define CallAENCallbackProc(userRoutine)        \
  261.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppAENCallbackProcInfo)
  262. #define CallSIMInitProc(userRoutine, SIMinfoPtr)        \
  263.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSIMInitProcInfo, (SIMinfoPtr))
  264. #define CallSIMActionProc(userRoutine, scsiPB, SIMGlobals)        \
  265.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSIMActionProcInfo, (scsiPB), (SIMGlobals))
  266. #define CallSCSIProc(userRoutine)        \
  267.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSCSIProcInfo)
  268. #define CallSCSIMakeCallbackProc(userRoutine, scsiPB)        \
  269.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSCSIMakeCallbackProcInfo, (scsiPB))
  270. #define CallSCSIInterruptPollProc(userRoutine, SIMGlobals)        \
  271.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSCSIInterruptPollProcInfo, (SIMGlobals))
  272. #else
  273. #define CallSCSICallbackProc(userRoutine, scsiPB)        \
  274.         (*(userRoutine))((scsiPB))
  275. #define CallAENCallbackProc(userRoutine)        \
  276.         (*(userRoutine))()
  277. #define CallSIMInitProc(userRoutine, SIMinfoPtr)        \
  278.         (*(userRoutine))((SIMinfoPtr))
  279. #define CallSIMActionProc(userRoutine, scsiPB, SIMGlobals)        \
  280.         (*(userRoutine))((scsiPB), (SIMGlobals))
  281. #define CallSCSIProc(userRoutine)        \
  282.         (*(userRoutine))()
  283. #define CallSCSIMakeCallbackProc(userRoutine, scsiPB)        \
  284.         (*(userRoutine))((scsiPB))
  285. #define CallSCSIInterruptPollProc(userRoutine, SIMGlobals)        \
  286.         (*(userRoutine))((SIMGlobals))
  287. #endif
  288.  
  289. enum {
  290.     handshakeDataLength            = 8,                            /* Handshake data length */
  291.     maxCDBLength                = 16,                            /* Space for the CDB bytes/pointer */
  292.     vendorIDLength                = 16                            /* ASCII string len for Vendor ID  */
  293. };
  294.  
  295. /* Define DeviceIdent structure */
  296. struct DeviceIdent {
  297.     UInt8                            diReserved;                    /* reserved                 */
  298.     UInt8                            bus;                        /* SCSI - Bus Number        */
  299.     UInt8                            targetID;                    /* SCSI - Target SCSI ID    */
  300.     UInt8                            LUN;                        /* SCSI - LUN                  */
  301. };
  302. typedef struct DeviceIdent DeviceIdent;
  303.  
  304. /* Command Descriptor Block structure */
  305. union CDB {
  306.     UInt8                            *cdbPtr;                    /* pointer to the CDB, or */
  307.     UInt8                            cdbBytes[maxCDBLength];        /* the actual CDB to send */
  308. };
  309. typedef union CDB CDB, *CDBPtr;
  310.  
  311. struct SGRecord {
  312.     Ptr                                SGAddr;
  313.     UInt32                            SGCount;
  314. };
  315. typedef struct SGRecord SGRecord;
  316.  
  317. /* SCSI Phases (used by SIMs to support the Original SCSI Manager */
  318.  
  319. enum {
  320.     kDataOutPhase,                                                /* Encoded MSG, C/D, I/O bits */
  321.     kDataInPhase,
  322.     kCommandPhase,
  323.     kStatusPhase,
  324.     kPhaseIllegal0,
  325.     kPhaseIllegal1,
  326.     kMessageOutPhase,
  327.     kMessageInPhase,
  328.     kBusFreePhase,                                                /* Additional Phases */
  329.     kArbitratePhase,
  330.     kSelectPhase,
  331.     kMessageInPhaseNACK                                            /* Message In Phase with ACK hanging on the bus */
  332. };
  333.  
  334. #define SCSIPBHdr                 \
  335.     struct SCSIHdr * qLink;        \
  336.     short    scsiReserved1;            \
  337.     UInt16    scsiPBLength;            \
  338.     UInt8    scsiFunctionCode;        \
  339.     UInt8    scsiReserved2;            \
  340.     OSErr    scsiResult;                \
  341.     DeviceIdent    scsiDevice;        \
  342.     SCSICallbackUPP    scsiCompletion;     \
  343.     UInt32    scsiFlags;                \
  344.     UInt8 *    scsiDriverStorage;        \
  345.     Ptr    scsiXPTprivate;            \
  346.     long    scsiReserved3;
  347. struct SCSIHdr {
  348.     struct SCSIHdr                    *qLink;
  349.     short                            scsiReserved1;
  350.     UInt16                            scsiPBLength;
  351.     UInt8                            scsiFunctionCode;
  352.     UInt8                            scsiReserved2;
  353.     OSErr                            scsiResult;
  354.     DeviceIdent                        scsiDevice;
  355.     SCSICallbackUPP                    scsiCompletion;
  356.     UInt32                            scsiFlags;
  357.     UInt8                            *scsiDriverStorage;
  358.     Ptr                                scsiXPTprivate;
  359.     long                            scsiReserved3;
  360. };
  361. typedef struct SCSIHdr SCSIHdr;
  362.  
  363. struct SCSI_PB {
  364.     struct SCSIHdr                    *qLink;
  365.     short                            scsiReserved1;
  366.     UInt16                            scsiPBLength;
  367.     UInt8                            scsiFunctionCode;
  368.     UInt8                            scsiReserved2;
  369.     OSErr                            scsiResult;
  370.     DeviceIdent                        scsiDevice;
  371.     SCSICallbackUPP                    scsiCompletion;
  372.     UInt32                            scsiFlags;
  373.     UInt8                            *scsiDriverStorage;
  374.     Ptr                                scsiXPTprivate;
  375.     long                            scsiReserved3;
  376. };
  377. typedef struct SCSI_PB SCSI_PB;
  378.  
  379. #define SCSI_IO_Macro             \
  380.     SCSIPBHdr                        \
  381.     UInt16    scsiResultFlags;        \
  382.     UInt16    scsiReserved3pt5;        \
  383.     UInt8 *    scsiDataPtr;            \
  384.     UInt32    scsiDataLength;            \
  385.     UInt8 *    scsiSensePtr;            \
  386.     UInt8    scsiSenseLength;            \
  387.     UInt8    scsiCDBLength;            \
  388.     UInt16    scsiSGListCount;        \
  389.     UInt32    scsiReserved4;            \
  390.     UInt8    scsiSCSIstatus;            \
  391.     SInt8    scsiSenseResidual;        \
  392.     UInt16    scsiReserved5;            \
  393.     long    scsiDataResidual;            \
  394.     CDB    scsiCDB;                    \
  395.     long    scsiTimeout;                \
  396.     UInt8 *    scsiReserved5pt5;        \
  397.     UInt16    scsiReserved5pt6;        \
  398.     UInt16    scsiIOFlags;            \
  399.     UInt8    scsiTagAction;            \
  400.     UInt8    scsiReserved6;            \
  401.     UInt16    scsiReserved7;            \
  402.     UInt16    scsiSelectTimeout;        \
  403.     UInt8    scsiDataType;            \
  404.     UInt8    scsiTransferType;        \
  405.     UInt32    scsiReserved8;            \
  406.     UInt32    scsiReserved9;            \
  407.     UInt16    scsiHandshake[handshakeDataLength];     \
  408.     UInt32    scsiReserved10;            \
  409.     UInt32    scsiReserved11;            \
  410.     struct SCSI_IO *scsiCommandLink;     \
  411.                                 \
  412.     UInt8    scsiSIMpublics[8];        \
  413.     UInt8    scsiAppleReserved6[8];     \
  414.                                 \
  415.                                 \
  416.                                 \
  417.     UInt16    scsiCurrentPhase;        \
  418.     short    scsiSelector;            \
  419.     OSErr    scsiOldCallResult;        \
  420.     UInt8    scsiSCSImessage;            \
  421.     UInt8    XPTprivateFlags;            \
  422.     UInt8    XPTextras[12];
  423. struct SCSI_IO {
  424.     struct SCSIHdr                    *qLink;
  425.     short                            scsiReserved1;
  426.     UInt16                            scsiPBLength;
  427.     UInt8                            scsiFunctionCode;
  428.     UInt8                            scsiReserved2;
  429.     OSErr                            scsiResult;
  430.     DeviceIdent                        scsiDevice;
  431.     SCSICallbackUPP                    scsiCompletion;
  432.     UInt32                            scsiFlags;
  433.     UInt8                            *scsiDriverStorage;
  434.     Ptr                                scsiXPTprivate;
  435.     long                            scsiReserved3;
  436.     UInt16                            scsiResultFlags;
  437.     UInt16                            scsiReserved3pt5;
  438.     UInt8                            *scsiDataPtr;
  439.     UInt32                            scsiDataLength;
  440.     UInt8                            *scsiSensePtr;
  441.     UInt8                            scsiSenseLength;
  442.     UInt8                            scsiCDBLength;
  443.     UInt16                            scsiSGListCount;
  444.     UInt32                            scsiReserved4;
  445.     UInt8                            scsiSCSIstatus;
  446.     SInt8                            scsiSenseResidual;
  447.     UInt16                            scsiReserved5;
  448.     long                            scsiDataResidual;
  449.     CDB                                scsiCDB;
  450.     long                            scsiTimeout;
  451.     UInt8                            *scsiReserved5pt5;
  452.     UInt16                            scsiReserved5pt6;
  453.     UInt16                            scsiIOFlags;
  454.     UInt8                            scsiTagAction;
  455.     UInt8                            scsiReserved6;
  456.     UInt16                            scsiReserved7;
  457.     UInt16                            scsiSelectTimeout;
  458.     UInt8                            scsiDataType;
  459.     UInt8                            scsiTransferType;
  460.     UInt32                            scsiReserved8;
  461.     UInt32                            scsiReserved9;
  462.     UInt16                            scsiHandshake[handshakeDataLength];
  463.     UInt32                            scsiReserved10;
  464.     UInt32                            scsiReserved11;
  465.     struct SCSI_IO                    *scsiCommandLink;
  466.     UInt8                            scsiSIMpublics[8];
  467.     UInt8                            scsiAppleReserved6[8];
  468.     UInt16                            scsiCurrentPhase;
  469.     short                            scsiSelector;
  470.     OSErr                            scsiOldCallResult;
  471.     UInt8                            scsiSCSImessage;
  472.     UInt8                            XPTprivateFlags;
  473.     UInt8                            XPTextras[12];
  474. };
  475. typedef struct SCSI_IO SCSI_IO;
  476.  
  477. typedef SCSI_IO SCSIExecIOPB;
  478.  
  479. /* Bus inquiry PB */
  480. struct SCSIBusInquiryPB {
  481.     struct SCSIHdr                    *qLink;
  482.     short                            scsiReserved1;
  483.     UInt16                            scsiPBLength;
  484.     UInt8                            scsiFunctionCode;
  485.     UInt8                            scsiReserved2;
  486.     OSErr                            scsiResult;
  487.     DeviceIdent                        scsiDevice;
  488.     SCSICallbackUPP                    scsiCompletion;
  489.     UInt32                            scsiFlags;
  490.     UInt8                            *scsiDriverStorage;
  491.     Ptr                                scsiXPTprivate;
  492.     long                            scsiReserved3;
  493.     UInt16                            scsiEngineCount;            /* <- Number of engines on HBA                         */
  494.     UInt16                            scsiMaxTransferType;        /* <- Number of transfer types for this HBA            */
  495.     UInt32                            scsiDataTypes;                /* <- which data types are supported by this SIM     */
  496.     UInt16                            scsiIOpbSize;                /* <- Size of SCSI_IO PB for this SIM/HBA             */
  497.     UInt16                            scsiMaxIOpbSize;            /* <- Size of max SCSI_IO PB for all SIM/HBAs         */
  498.     UInt32                            scsiFeatureFlags;            /* <- Supported features flags field                 */
  499.     UInt8                            scsiVersionNumber;            /* <- Version number for the SIM/HBA                 */
  500.     UInt8                            scsiHBAInquiry;                /* <- Mimic of INQ byte 7 for the HBA                 */
  501.     UInt8                            scsiTargetModeFlags;        /* <- Flags for target mode support                 */
  502.     UInt8                            scsiScanFlags;                /* <- Scan related feature flags                     */
  503.     UInt32                            scsiSIMPrivatesPtr;            /* <- Ptr to SIM private data area                     */
  504.     UInt32                            scsiSIMPrivatesSize;        /* <- Size of SIM private data area                 */
  505.     UInt32                            scsiAsyncFlags;                /* <- Event cap. for Async Callback                 */
  506.     UInt8                            scsiHiBusID;                /* <- Highest path ID in the subsystem              */
  507.     UInt8                            scsiInitiatorID;            /* <- ID of the HBA on the SCSI bus                 */
  508.     UInt16                            scsiBIReserved0;            /*                                                    */
  509.     UInt32                            scsiBIReserved1;            /* <-                                                  */
  510.     UInt32                            scsiFlagsSupported;            /* <- which scsiFlags are supported                 */
  511.     UInt16                            scsiIOFlagsSupported;        /* <- which scsiIOFlags are supported                 */
  512.     UInt16                            scsiWeirdStuff;                /* <-                                                 */
  513.     UInt16                            scsiMaxTarget;                /* <- maximum Target number supported                 */
  514.     UInt16                            scsiMaxLUN;                    /* <- maximum Logical Unit number supported         */
  515.     char                            scsiSIMVendor[vendorIDLength]; /* <- Vendor ID of SIM (or XPT if bus<FF)         */
  516.     char                            scsiHBAVendor[vendorIDLength]; /* <- Vendor ID of the HBA                         */
  517.     char                            scsiControllerFamily[vendorIDLength]; /* <- Family of SCSI Controller                 */
  518.     char                            scsiControllerType[vendorIDLength]; /* <- Specific Model of SCSI Controller used     */
  519.     char                            scsiXPTversion[4];            /* <- version number of XPT                         */
  520.     char                            scsiSIMversion[4];            /* <- version number of SIM                         */
  521.     char                            scsiHBAversion[4];            /* <- version number of HBA                         */
  522.     UInt8                            scsiHBAslotType;            /* <- type of "slot" that this HBA is in            */
  523.     UInt8                            scsiHBAslotNumber;            /* <- slot number of this HBA                         */
  524.     UInt16                            scsiSIMsRsrcID;                /* <- resource ID of this SIM                         */
  525.     UInt16                            scsiBIReserved3;            /* <-                                                 */
  526.     UInt16                            scsiAdditionalLength;        /* <- additional BusInquiry PB len                    */
  527. };
  528. typedef struct SCSIBusInquiryPB SCSIBusInquiryPB;
  529.  
  530. /* Abort SIM Request PB */
  531. struct SCSIAbortCommandPB {
  532.     struct SCSIHdr                    *qLink;
  533.     short                            scsiReserved1;
  534.     UInt16                            scsiPBLength;
  535.     UInt8                            scsiFunctionCode;
  536.     UInt8                            scsiReserved2;
  537.     OSErr                            scsiResult;
  538.     DeviceIdent                        scsiDevice;
  539.     SCSICallbackUPP                    scsiCompletion;
  540.     UInt32                            scsiFlags;
  541.     UInt8                            *scsiDriverStorage;
  542.     Ptr                                scsiXPTprivate;
  543.     long                            scsiReserved3;
  544.     SCSI_IO                            *scsiIOptr;                    /* Pointer to the PB to abort                        */
  545. };
  546. typedef struct SCSIAbortCommandPB SCSIAbortCommandPB;
  547.  
  548. /* Terminate I/O Process Request PB */
  549. struct SCSITerminateIOPB {
  550.     struct SCSIHdr                    *qLink;
  551.     short                            scsiReserved1;
  552.     UInt16                            scsiPBLength;
  553.     UInt8                            scsiFunctionCode;
  554.     UInt8                            scsiReserved2;
  555.     OSErr                            scsiResult;
  556.     DeviceIdent                        scsiDevice;
  557.     SCSICallbackUPP                    scsiCompletion;
  558.     UInt32                            scsiFlags;
  559.     UInt8                            *scsiDriverStorage;
  560.     Ptr                                scsiXPTprivate;
  561.     long                            scsiReserved3;
  562.     SCSI_IO                            *scsiIOptr;                    /* Pointer to the PB to terminate                     */
  563. };
  564. typedef struct SCSITerminateIOPB SCSITerminateIOPB;
  565.  
  566. /* Reset SCSI Bus PB */
  567. struct SCSIResetBusPB {
  568.     struct SCSIHdr                    *qLink;
  569.     short                            scsiReserved1;
  570.     UInt16                            scsiPBLength;
  571.     UInt8                            scsiFunctionCode;
  572.     UInt8                            scsiReserved2;
  573.     OSErr                            scsiResult;
  574.     DeviceIdent                        scsiDevice;
  575.     SCSICallbackUPP                    scsiCompletion;
  576.     UInt32                            scsiFlags;
  577.     UInt8                            *scsiDriverStorage;
  578.     Ptr                                scsiXPTprivate;
  579.     long                            scsiReserved3;
  580. };
  581. typedef struct SCSIResetBusPB SCSIResetBusPB;
  582.  
  583. /* Reset SCSI Device PB */
  584. struct SCSIResetDevicePB {
  585.     struct SCSIHdr                    *qLink;
  586.     short                            scsiReserved1;
  587.     UInt16                            scsiPBLength;
  588.     UInt8                            scsiFunctionCode;
  589.     UInt8                            scsiReserved2;
  590.     OSErr                            scsiResult;
  591.     DeviceIdent                        scsiDevice;
  592.     SCSICallbackUPP                    scsiCompletion;
  593.     UInt32                            scsiFlags;
  594.     UInt8                            *scsiDriverStorage;
  595.     Ptr                                scsiXPTprivate;
  596.     long                            scsiReserved3;
  597. };
  598. typedef struct SCSIResetDevicePB SCSIResetDevicePB;
  599.  
  600. /* Release SIM Queue PB */
  601. struct SCSIReleaseQPB {
  602.     struct SCSIHdr                    *qLink;
  603.     short                            scsiReserved1;
  604.     UInt16                            scsiPBLength;
  605.     UInt8                            scsiFunctionCode;
  606.     UInt8                            scsiReserved2;
  607.     OSErr                            scsiResult;
  608.     DeviceIdent                        scsiDevice;
  609.     SCSICallbackUPP                    scsiCompletion;
  610.     UInt32                            scsiFlags;
  611.     UInt8                            *scsiDriverStorage;
  612.     Ptr                                scsiXPTprivate;
  613.     long                            scsiReserved3;
  614. };
  615. typedef struct SCSIReleaseQPB SCSIReleaseQPB;
  616.  
  617. /* SCSI Get Virtual ID Info PB */
  618. struct SCSIGetVirtualIDInfoPB {
  619.     struct SCSIHdr                    *qLink;
  620.     short                            scsiReserved1;
  621.     UInt16                            scsiPBLength;
  622.     UInt8                            scsiFunctionCode;
  623.     UInt8                            scsiReserved2;
  624.     OSErr                            scsiResult;
  625.     DeviceIdent                        scsiDevice;
  626.     SCSICallbackUPP                    scsiCompletion;
  627.     UInt32                            scsiFlags;
  628.     UInt8                            *scsiDriverStorage;
  629.     Ptr                                scsiXPTprivate;
  630.     long                            scsiReserved3;
  631.     UInt16                            scsiOldCallID;                /* -> SCSI ID of device in question             */
  632.     Boolean                            scsiExists;                    /* <- true if device exists                     */
  633.     SInt8                            filler;
  634. };
  635. typedef struct SCSIGetVirtualIDInfoPB SCSIGetVirtualIDInfoPB;
  636.  
  637. /* Create/Lookup/Remove RefNum for Device PB */
  638. struct SCSIDriverPB {
  639.     struct SCSIHdr                    *qLink;
  640.     short                            scsiReserved1;
  641.     UInt16                            scsiPBLength;
  642.     UInt8                            scsiFunctionCode;
  643.     UInt8                            scsiReserved2;
  644.     OSErr                            scsiResult;
  645.     DeviceIdent                        scsiDevice;
  646.     SCSICallbackUPP                    scsiCompletion;
  647.     UInt32                            scsiFlags;
  648.     UInt8                            *scsiDriverStorage;
  649.     Ptr                                scsiXPTprivate;
  650.     long                            scsiReserved3;
  651.     short                            scsiDriver;                    /* -> DriverRefNum, For SetDriver, <- For GetNextDriver */
  652.     UInt16                            scsiDriverFlags;            /* <> Details of driver/device                     */
  653.     DeviceIdent                        scsiNextDevice;                /* <- DeviceIdent of the NEXT Item in the list  */
  654. };
  655. typedef struct SCSIDriverPB SCSIDriverPB;
  656.  
  657. /* Load Driver PB */
  658. struct SCSILoadDriverPB {
  659.     struct SCSIHdr                    *qLink;
  660.     short                            scsiReserved1;
  661.     UInt16                            scsiPBLength;
  662.     UInt8                            scsiFunctionCode;
  663.     UInt8                            scsiReserved2;
  664.     OSErr                            scsiResult;
  665.     DeviceIdent                        scsiDevice;
  666.     SCSICallbackUPP                    scsiCompletion;
  667.     UInt32                            scsiFlags;
  668.     UInt8                            *scsiDriverStorage;
  669.     Ptr                                scsiXPTprivate;
  670.     long                            scsiReserved3;
  671.     short                            scsiLoadedRefNum;            /* <- SIM returns refnum of driver                     */
  672.     Boolean                            scsiDiskLoadFailed;            /* -> if true, indicates call after failure to load */
  673.     SInt8                            filler;
  674. };
  675. typedef struct SCSILoadDriverPB SCSILoadDriverPB;
  676.  
  677. /* Defines for the scsiTransferType field */
  678.  
  679. enum {
  680.     scsiTransferBlind            = 0,
  681.     scsiTransferPolled
  682. };
  683.  
  684. /* Defines for the scsiDataType field */
  685. enum {
  686.     scsiDataBuffer                = 0,                            /* single contiguous buffer supplied                  */
  687.     scsiDataTIB                    = 1,                            /* TIB supplied (ptr in scsiDataPtr)                 */
  688.     scsiDataSG                    = 2                                /* scatter/gather list supplied                      */
  689. };
  690.  
  691. /* Defines for the SCSIMgr scsiResult field in the PB header. */
  692. /*  $E100 thru  E1FF */
  693. /* -$1EFF thru -1E00 */
  694. /* -#7935 thru -7681  */
  695. /* = 0xE100 */
  696. enum {
  697.     scsiErrorBase                = -7936
  698. };
  699.  
  700. enum {
  701.     scsiRequestInProgress        = 1,                            /* 1     = PB request is in progress             */
  702. /* Execution failed  00-2F */
  703.     scsiRequestAborted            = scsiErrorBase + 2,            /* -7934 = PB request aborted by the host         */
  704.     scsiUnableToAbort            = scsiErrorBase + 3,            /* -7933 = Unable to Abort PB request             */
  705.     scsiNonZeroStatus            = scsiErrorBase + 4,            /* -7932 = PB request completed with an err     */
  706.     scsiUnused05                = scsiErrorBase + 5,            /* -7931 =                                      */
  707.     scsiUnused06                = scsiErrorBase + 6,            /* -7930 =                                      */
  708.     scsiUnused07                = scsiErrorBase + 7,            /* -7929 =                                      */
  709.     scsiUnused08                = scsiErrorBase + 8,            /* -7928 =                                      */
  710.     scsiUnableToTerminate        = scsiErrorBase + 9,            /* -7927 = Unable to Terminate I/O PB req         */
  711.     scsiSelectTimeout            = scsiErrorBase + 10,            /* -7926 = Target selection timeout             */
  712.     scsiCommandTimeout            = scsiErrorBase + 11,            /* -7925 = Command timeout                      */
  713.     scsiIdentifyMessageRejected    = scsiErrorBase + 12,            /* -7924 =                                      */
  714.     scsiMessageRejectReceived    = scsiErrorBase + 13,            /* -7923 = Message reject received                 */
  715.     scsiSCSIBusReset            = scsiErrorBase + 14,            /* -7922 = SCSI bus reset sent/received         */
  716.     scsiParityError                = scsiErrorBase + 15,            /* -7921 = Uncorrectable parity error occured     */
  717.     scsiAutosenseFailed            = scsiErrorBase + 16,            /* -7920 = Autosense: Request sense cmd fail     */
  718.     scsiUnused11                = scsiErrorBase + 17,            /* -7919 =                                      */
  719.     scsiDataRunError            = scsiErrorBase + 18,            /* -7918 = Data overrun/underrun error          */
  720.     scsiUnexpectedBusFree        = scsiErrorBase + 19,            /* -7917 = Unexpected BUS free                     */
  721.     scsiSequenceFailed            = scsiErrorBase + 20,            /* -7916 = Target bus phase sequence failure     */
  722.     scsiWrongDirection            = scsiErrorBase + 21,            /* -7915 = Data phase was in wrong direction     */
  723.     scsiUnused16                = scsiErrorBase + 22,            /* -7914 =                                      */
  724.     scsiBDRsent                    = scsiErrorBase + 23,            /* -7913 = A SCSI BDR msg was sent to target     */
  725.     scsiTerminated                = scsiErrorBase + 24,            /* -7912 = PB request terminated by the host     */
  726.     scsiNoNexus                    = scsiErrorBase + 25,            /* -7911 = Nexus is not established             */
  727.     scsiCDBReceived                = scsiErrorBase + 26,            /* -7910 = The SCSI CDB has been received         */
  728. /* Couldn't begin execution  30-3F */
  729.     scsiTooManyBuses            = scsiErrorBase + 48,            /* -7888 = Register failed because we're full    */
  730.     scsiBusy                    = scsiErrorBase + 49,            /* -7887 = SCSI subsystem is busy                 */
  731.     scsiProvideFail                = scsiErrorBase + 50,            /* -7886 = Unable to provide requ. capability    */
  732.     scsiDeviceNotThere            = scsiErrorBase + 51,            /* -7885 = SCSI device not installed/there      */
  733.     scsiNoHBA                    = scsiErrorBase + 52,            /* -7884 = No HBA detected Error                 */
  734.     scsiDeviceConflict            = scsiErrorBase + 53,            /* -7883 = sorry, max 1 refNum per DeviceIdent     */
  735.     scsiNoSuchXref                = scsiErrorBase + 54,            /* -7882 = no such RefNum xref                     */
  736.     scsiQLinkInvalid            = scsiErrorBase + 55,            /* -7881 = pre-linked PBs not supported            
  737.                                                                    (The QLink field was nonzero)        */
  738. /* Parameter errors  40-7F */
  739.     scsiPBLengthError            = scsiErrorBase + 64,            /* -7872 = (scsiPBLength is insuf'ct/invalid     */
  740.     scsiFunctionNotAvailable    = scsiErrorBase + 65,            /* -7871 = The requ. func is not available      */
  741.     scsiRequestInvalid            = scsiErrorBase + 66,            /* -7870 = PB request is invalid                 */
  742.     scsiBusInvalid                = scsiErrorBase + 67,            /* -7869 = Bus ID supplied is invalid              */
  743.     scsiTIDInvalid                = scsiErrorBase + 68,            /* -7868 = Target ID supplied is invalid         */
  744.     scsiLUNInvalid                = scsiErrorBase + 69,            /* -7867 = LUN supplied is invalid              */
  745.     scsiIDInvalid                = scsiErrorBase + 70,            /* -7866 = The initiator ID is invalid          */
  746.     scsiDataTypeInvalid            = scsiErrorBase + 71,            /* -7865 = scsiDataType requested not supported */
  747.     scsiTransferTypeInvalid        = scsiErrorBase + 72,            /* -7864 = scsiTransferType field is too high     */
  748.     scsiCDBLengthInvalid        = scsiErrorBase + 73            /* -7863 = scsiCDBLength field is too big         */
  749. };
  750.  
  751. enum {
  752.     scsiExecutionErrors            = scsiErrorBase,
  753.     scsiNotExecutedErrors        = scsiTooManyBuses,
  754.     scsiParameterErrors            = scsiPBLengthError
  755. };
  756.  
  757. /* Defines for the scsiResultFlags field */
  758. enum {
  759.     scsiSIMQFrozen                = 0x0001,                        /* The SIM queue is frozen w/this err            */
  760.     scsiAutosenseValid            = 0x0002,                        /* Autosense data valid for target              */
  761.     scsiBusNotFree                = 0x0004                        /* At time of callback, SCSI bus is not free    */
  762. };
  763.  
  764. /* Defines for the bit numbers of the scsiFlags field in the PB header for the SCSIExecIO function */
  765. enum {
  766.     kbSCSIDisableAutosense        = 29,                            /* Disable auto sense feature                     */
  767.     kbSCSIFlagReservedA            = 28,                            /*                                              */
  768.     kbSCSIFlagReserved0            = 27,                            /*                                              */
  769.     kbSCSICDBLinked                = 26,                            /* The PB contains a linked CDB                    */
  770.     kbSCSIQEnable                = 25,                            /* Target queue actions are enabled                */
  771.     kbSCSICDBIsPointer            = 24,                            /* The CDB field contains a pointer                */
  772.     kbSCSIFlagReserved1            = 23,                            /*                                                 */
  773.     kbSCSIInitiateSyncData        = 22,                            /* Attempt Sync data xfer and SDTR                */
  774.     kbSCSIDisableSyncData        = 21,                            /* Disable sync, go to async                    */
  775.     kbSCSISIMQHead                = 20,                            /* Place PB at the head of SIM Q                */
  776.     kbSCSISIMQFreeze            = 19,                            /* Return the SIM Q to frozen state                */
  777.     kbSCSISIMQNoFreeze            = 18,                            /* Disallow SIM Q freezing                        */
  778.     kbSCSIDoDisconnect            = 17,                            /* Definitely do disconnect                        */
  779.     kbSCSIDontDisconnect        = 16,                            /* Definitely don't disconnect                    */
  780.     kbSCSIDataReadyForDMA        = 15,                            /* Data buffer(s) are ready for DMA                */
  781.     kbSCSIFlagReserved3            = 14,                            /*                                                 */
  782.     kbSCSIDataPhysical            = 13,                            /* SG/Buffer data ptrs are physical                */
  783.     kbSCSISensePhysical            = 12,                            /* Autosense buffer ptr is physical                */
  784.     kbSCSIFlagReserved5            = 11,                            /*                                                 */
  785.     kbSCSIFlagReserved6            = 10,                            /*                                                 */
  786.     kbSCSIFlagReserved7            = 9,                            /*                                                 */
  787.     kbSCSIFlagReserved8            = 8,                            /*                                                 */
  788.     kbSCSIDataBufferValid        = 7,                            /* Data buffer valid                            */
  789.     kbSCSIStatusBufferValid        = 6,                            /* Status buffer valid                             */
  790.     kbSCSIMessageBufferValid    = 5,                            /* Message buffer valid                            */
  791.     kbSCSIFlagReserved9            = 4                                /*                                              */
  792. };
  793.  
  794. /* Defines for the bit masks of the scsiFlags field */
  795. enum {
  796.     scsiDirectionMask            = 0xC0000000,                    /* Data direction mask                        */
  797.     scsiDirectionNone            = 0xC0000000,                    /* Data direction (11: no data)                */
  798.     scsiDirectionReserved        = 0x00000000,                    /* Data direction (00: reserved)            */
  799.     scsiDirectionOut            = 0x80000000,                    /* Data direction (10: DATA OUT)            */
  800.     scsiDirectionIn                = 0x40000000,                    /* Data direction (01: DATA IN)                */
  801.     scsiDisableAutosense        = 0x20000000,                    /* Disable auto sense feature                */
  802.     scsiFlagReservedA            = 0x10000000,                    /*                                             */
  803.     scsiFlagReserved0            = 0x08000000,                    /*                                             */
  804.     scsiCDBLinked                = 0x04000000,                    /* The PB contains a linked CDB                */
  805.     scsiQEnable                    = 0x02000000,                    /* Target queue actions are enabled            */
  806.     scsiCDBIsPointer            = 0x01000000,                    /* The CDB field contains a pointer            */
  807.     scsiFlagReserved1            = 0x00800000,                    /*                                             */
  808.     scsiInitiateSyncData        = 0x00400000,                    /* Attempt Sync data xfer and SDTR            */
  809.     scsiDisableSyncData            = 0x00200000,                    /* Disable sync, go to async                */
  810.     scsiSIMQHead                = 0x00100000,                    /* Place PB at the head of SIM Q            */
  811.     scsiSIMQFreeze                = 0x00080000,                    /* Return the SIM Q to frozen state            */
  812.     scsiSIMQNoFreeze            = 0x00040000,                    /* Disallow SIM Q freezing                    */
  813.     scsiDoDisconnect            = 0x00020000,                    /* Definitely do disconnect                    */
  814.     scsiDontDisconnect            = 0x00010000,                    /* Definitely don't disconnect                */
  815.     scsiDataReadyForDMA            = 0x00008000,                    /* Data buffer(s) are ready for DMA            */
  816.     scsiFlagReserved3            = 0x00004000,                    /*  */
  817.     scsiDataPhysical            = 0x00002000,                    /* SG/Buffer data ptrs are physical            */
  818.     scsiSensePhysical            = 0x00001000,                    /* Autosense buffer ptr is physical            */
  819.     scsiFlagReserved5            = 0x00000800,                    /*                                          */
  820.     scsiFlagReserved6            = 0x00000400,                    /*                                             */
  821.     scsiFlagReserved7            = 0x00000200,                    /*                                             */
  822.     scsiFlagReserved8            = 0x00000100                    /*                                             */
  823. };
  824.  
  825. /* bit masks for the scsiIOFlags field in SCSIExecIOPB */
  826. enum {
  827.     scsiNoParityCheck            = 0x0002,                        /* disable parity checking                             */
  828.     scsiDisableSelectWAtn        = 0x0004,                        /* disable select w/Atn                              */
  829.     scsiSavePtrOnDisconnect        = 0x0008,                        /* do SaveDataPointer upon Disconnect msg             */
  830.     scsiNoBucketIn                = 0x0010,                        /* don’t bit bucket in during this I/O                 */
  831.     scsiNoBucketOut                = 0x0020,                        /* don’t bit bucket out during this I/O             */
  832.     scsiDisableWide                = 0x0040,                        /* disable wide transfer negotiation                 */
  833.     scsiInitiateWide            = 0x0080,                        /* initiate wide transfer negotiation                 */
  834.     scsiRenegotiateSense        = 0x0100,                        /* renegotiate sync/wide before issuing autosense     */
  835.     scsiDisableDiscipline        = 0x0200,                        /* disable parameter checking on SCSIExecIO calls    */
  836.     scsiIOFlagReserved0080        = 0x0080,                        /*                                                  */
  837.     scsiIOFlagReserved8000        = 0x8000                        /*                                                     */
  838. };
  839.  
  840. /* Defines for the SIM/HBA queue actions.  These values are used in the */
  841. /* SCSIExecIOPB, for the queue action field. [These values should match the */
  842. /* defines from some other include file for the SCSI message phases.  We may */
  843. /* not need these definitions here. ] */
  844. enum {
  845.     scsiSimpleQTag                = 0x20,                            /* Tag for a simple queue                                 */
  846.     scsiHeadQTag                = 0x21,                            /* Tag for head of queue                                  */
  847.     scsiOrderedQTag                = 0x22                            /* Tag for ordered queue                                 */
  848. };
  849.  
  850. /* Defines for the Bus Inquiry PB fields. */
  851. /* scsiHBAInquiry field bits */
  852. enum {
  853.     scsiBusMDP                    = 0x80,                            /* Supports Modify Data Pointer message                        */
  854.     scsiBusWide32                = 0x40,                            /* Supports 32 bit wide SCSI                                */
  855.     scsiBusWide16                = 0x20,                            /* Supports 16 bit wide SCSI                                */
  856.     scsiBusSDTR                    = 0x10,                            /* Supports Sync Data Transfer Req message                    */
  857.     scsiBusLinkedCDB            = 0x08,                            /* Supports linked CDBs                                        */
  858.     scsiBusTagQ                    = 0x02,                            /* Supports tag queue message                                */
  859.     scsiBusSoftReset            = 0x01                            /* Supports soft reset                                        */
  860. };
  861.  
  862. /* scsiDataTypes field bits  */
  863. /*    bits 0->15 Apple-defined, 16->30 3rd-party unique, 31 = reserved */
  864. enum {
  865.     scsiBusDataTIB                = (1 << scsiDataTIB),            /* TIB supplied (ptr in scsiDataPtr)        */
  866.     scsiBusDataBuffer            = (1 << scsiDataBuffer),        /* single contiguous buffer supplied         */
  867.     scsiBusDataSG                = (1 << scsiDataSG),            /* scatter/gather list supplied             */
  868.     scsiBusDataReserved            = 0x80000000                    /*                                           */
  869. };
  870.  
  871. /* scsiScanFlags field bits */
  872. enum {
  873.     scsiBusScansDevices            = 0x80,                            /* Bus scans for and maintains device list            */
  874.     scsiBusScansOnInit            = 0x40,                            /* Bus scans performed at power-up/reboot            */
  875.     scsiBusLoadsROMDrivers        = 0x20                            /* may load ROM drivers to support targets             */
  876. };
  877.  
  878. /* scsiFeatureFlags field bits */
  879. enum {
  880.     scsiBusInternalExternalMask    = 0x000000C0,                    /* bus internal/external mask                    */
  881.     scsiBusInternalExternalUnknown = 0x00000000,                /* not known whether bus is inside or outside     */
  882.     scsiBusInternalExternal        = 0x000000C0,                    /* bus goes inside and outside the box             */
  883.     scsiBusInternal                = 0x00000080,                    /* bus goes inside the box                         */
  884.     scsiBusExternal                = 0x00000040,                    /* bus goes outside the box                     */
  885.     scsiBusCacheCoherentDMA        = 0x00000020,                    /* DMA is cache coherent                         */
  886.     scsiBusOldCallCapable        = 0x00000010,                    /* SIM is old call capable                         */
  887.     scsiBusDifferential            = 0x00000004,                    /* Single Ended (0) or Differential (1)         */
  888.     scsiBusFastSCSI                = 0x00000002,                    /* HBA supports fast SCSI                         */
  889.     scsiBusDMAavailable            = 0x00000001                    /* DMA is available                             */
  890. };
  891.  
  892. /* scsiWeirdStuff field bits */
  893. enum {
  894.     scsiOddDisconnectUnsafeRead1 = 0x0001,                        /* Disconnects on odd byte boundries are unsafe with DMA and/or blind reads */
  895.     scsiOddDisconnectUnsafeWrite1 = 0x0002,                        /* Disconnects on odd byte boundries are unsafe with DMA and/or blind writes */
  896.     scsiBusErrorsUnsafe            = 0x0004,                        /* Non-handshaked delays or disconnects during blind transfers may cause a crash */
  897.     scsiRequiresHandshake        = 0x0008,                        /* Non-handshaked delays or disconnects during blind transfers may cause data corruption */
  898.     scsiTargetDrivenSDTRSafe    = 0x0010                        /* Targets which initiate synchronous negotiations are supported */
  899. };
  900.  
  901. /* scsiHBAslotType values */
  902. enum {
  903.     scsiMotherboardBus            = 0x01,                            /* A built in Apple supplied bus                     */
  904.     scsiNuBus                    = 0x02,                            /* A SIM on a NuBus card                             */
  905.     scsiPDSBus                    = 0x03,                            /*    "  on a PDS card                                */
  906.     scsiPCIBus                    = 0x04,                            /*    "  on a PCI bus card                            */
  907.     scsiPCMCIABus                = 0x05,                            /*    "  on a PCMCIA card                            */
  908.     scsiFireWireBridgeBus        = 0x06                            /*    "  connected through a FireWire bridge        */
  909. };
  910.  
  911. /* Defines for the scsiDriverFlags field (in SCSIDriverPB) */
  912. enum {
  913.     scsiDeviceSensitive            = 0x0001,                        /* Only driver should access this device                */
  914.     scsiDeviceNoOldCallAccess    = 0x0002                        /* no old call access to this device                     */
  915. };
  916.  
  917. /*  SIMInitInfo PB */
  918. /* directions are for SCSIRegisterBus call ( -> parm, <- result)             */
  919. struct SIMInitInfo {
  920.     UInt8                            *SIMstaticPtr;                /* <- alloc. ptr to the SIM's static vars                 */
  921.     long                            staticSize;                    /* -> num bytes SIM needs for static vars                 */
  922.     SIMInitUPP                        SIMInit;                    /* -> pointer to the SIM init routine                     */
  923.     SIMActionUPP                    SIMAction;                    /* -> pointer to the SIM action routine                 */
  924.     SCSIUPP                            SIM_ISR;                    /*       reserved                                             */
  925.     SCSIInterruptPollUPP            SIMInterruptPoll;            /* -> pointer to the SIM interrupt poll routine            */
  926.     SIMActionUPP                    NewOldCall;                    /* -> pointer to the SIM NewOldCall routine                */
  927.     UInt16                            ioPBSize;                    /* -> size of SCSI_IO_PBs required for this SIM            */
  928.     Boolean                            oldCallCapable;                /* -> true if this SIM can handle old-API calls            */
  929.     UInt8                            simInfoUnused1;                /*       reserved                                            */
  930.     long                            simInternalUse;                /* xx not affected or viewed by XPT                        */
  931.     SCSIUPP                            XPT_ISR;                    /*    reserved                                            */
  932.     SCSIUPP                            EnteringSIM;                /* <- ptr to the EnteringSIM routine                    */
  933.     SCSIUPP                            ExitingSIM;                    /* <- ptr to the ExitingSIM routine                        */
  934.     SCSIMakeCallbackUPP                MakeCallback;                /* <- the XPT layer’s SCSIMakeCallback routine            */
  935.     UInt16                            busID;                        /* <- bus number for the registered bus                    */
  936.     UInt16                            simInfoUnused3;                /* <- reserved                                            */
  937.     long                            simInfoUnused4;                /* <- reserved                                            */
  938. };
  939. typedef struct SIMInitInfo SIMInitInfo;
  940.  
  941. /* Glue between SCSI calls and SCSITrap format */
  942.  
  943. enum {
  944.     xptSCSIAction                = 0x0001,
  945.     xptSCSIRegisterBus            = 0x0002,
  946.     xptSCSIDeregisterBus        = 0x0003,
  947.     xptSCSIReregisterBus        = 0x0004,
  948.     xptSCSIKillXPT                = 0x0005,                        /* kills Mini-XPT after transition */
  949.     xptSCSIInitialize            = 0x000A                        /* Initialize the SCSI manager */
  950. };
  951.  
  952. /* moveq #kSCSIx, D0;  _SCSIAtomic */
  953.  
  954. #if !GENERATINGCFM
  955. #pragma parameter __D0 SCSIAction(__A0)
  956. #endif
  957. extern pascal OSErr SCSIAction(SCSI_PB *parameterBlock)
  958.  TWOWORDINLINE(0x7001, 0xA089);
  959.  
  960. #if !GENERATINGCFM
  961. #pragma parameter __D0 SCSIRegisterBus(__A0)
  962. #endif
  963. extern pascal OSErr SCSIRegisterBus(SIMInitInfo *parameterBlock)
  964.  TWOWORDINLINE(0x7002, 0xA089);
  965.  
  966. #if !GENERATINGCFM
  967. #pragma parameter __D0 SCSIDeregisterBus(__A0)
  968. #endif
  969. extern pascal OSErr SCSIDeregisterBus(SCSI_PB *parameterBlock)
  970.  TWOWORDINLINE(0x7003, 0xA089);
  971.  
  972. #if !GENERATINGCFM
  973. #pragma parameter __D0 SCSIReregisterBus(__A0)
  974. #endif
  975. extern pascal OSErr SCSIReregisterBus(SIMInitInfo *parameterBlock)
  976.  TWOWORDINLINE(0x7004, 0xA089);
  977.  
  978. #if !GENERATINGCFM
  979. #pragma parameter __D0 SCSIKillXPT(__A0)
  980. #endif
  981. extern pascal OSErr SCSIKillXPT(SIMInitInfo *parameterBlock)
  982.  TWOWORDINLINE(0x7005, 0xA089);
  983.  
  984. #ifdef __CFM68K__
  985. #pragma lib_export off
  986. #endif
  987.  
  988. #if GENERATINGPOWERPC
  989. #pragma options align=reset
  990. #endif
  991.  
  992. #ifdef __cplusplus
  993. }
  994. #endif
  995.  
  996. #endif /* __SCSI__ */
  997.